home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / kvik / text / posting1 / text0000.txt < prev   
Encoding:
Text File  |  1995-02-22  |  15.1 KB  |  412 lines

  1.  
  2. THE KVIKKALKUL PROGRAMMING LANGUAGE
  3.  
  4. Note: this message contains top secret information of the Swedish Navy.
  5.       Possession of this information in Sweden can (and will in most cases)
  6.       lead to Capital Punishment. DO NOT DISTRIBUTE THIS INFORMATION
  7.       TO SWEDEN!!! 
  8.       
  9. INTRODUCTION
  10.  
  11. When I worked for the Swedish Navy in 1957 as a programmer, my task was to
  12. write programs for the SABINA computer, one of the first transistorised
  13. computers in the world, manufactured by SAAB for use on Swedish submarines.
  14. The computer was located on a test facility in Karlskrona, the Swedish 
  15. Navy base. All programming was done in a funky language called 'kvikkalkul',
  16. a language that makes Assembler (or even INTERCAL) look friendly. 
  17. The mere existence of SABINA and the programming language 'kvikkalkul' was and
  18. still is top secret. Other top secrets of that age leaked into publicity long
  19. ago, but this one is still preserved. Until now.  
  20.  
  21. Apart from real-time submarine applications such as guided torpedo control, I
  22. did an accounting package in kvikkalkul as well. 
  23.  
  24. THE CHARACTER SET
  25.  
  26. Kvikkalkul was typed on Baudot encoded teletype machines. Programs were
  27. stored on paper tape. As you might know, Baudot is a five bit code. The
  28. machine can be in two modes, the 'letters' mode and the 'figures' mode.
  29. In 'letters' mode you have the 26 letter symbols, in 'figures' mode you have
  30. the ten digits and some punctuation marks. The codes to switch to the 'letters'
  31. or 'figures' mode, the space, the linefeed and carriage return codes are
  32. available in both modes. Kvikkalkul used symbols from the 'figures' mode
  33. exclusively, therefore it had no letters. If you typed letters in your program
  34. they were interpreted as the corresponding 'figures' mode symbols. Kvikkalkul
  35. had no comments or text literals either; there were no letters in the
  36. language. Period.
  37.  
  38. The available symbols were: CR/LF, Space, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  39. period(.), comma(,), quote("), colon(:), dash(-), slash(/) and the left and right
  40. parentheses ( and ). 
  41.  
  42. Each statement was on a separate line. 
  43.  
  44. THE NUMBER SYSTEM
  45.  
  46. The only data type in kvikkalkul was the signed fixed point fractional number.
  47. The reason for this was that the precision of numbers could be extended without
  48. breaking existing programs. Kvikkalkul was designed for such things as real
  49. time control, so this seemed sensible. The downside was that you had no 
  50. integers or whatever other data type. Even arrays were indexed with
  51. fractional numbers.
  52.  
  53. The minimum precision you could rely on was 15 bits. This is a sign bit and
  54. 14 significant fractional bits. The representation was one's complement.
  55. The data word with all bits set (minus zero) denoted overflow. There were
  56. 16383 positive numbers, 0 and 16383 negative numbers. The minimum number
  57. was a bit higher than -1 and the maximum number was a bit lower than 1.  
  58. You didn't have numbers greater than 1, even not 1 itself. 
  59.  
  60. Every operation that would produce a result outside the range (-1,1)
  61. would return the special overflow value with all bits set.
  62.  
  63. Numbers were entered as decimal fractions, starting with a comma (the Swedish
  64. representation for decimal point).  e.g. ,125 denotes 1/8.
  65.  
  66. Kvikkalkul had the following operators
  67.  
  68. Assignment/pointer
  69. (-  Assignment
  70. -)  Points to
  71. ((  Previous
  72. ))  Next
  73.  
  74. Arithmetic
  75. -/- Plus
  76.   --  Minus
  77. )(  Times
  78. -:- Divide
  79. -   Unary Minus
  80.  
  81. Relational
  82. ::  Equal
  83. :/: Not Equal  
  84. (   Less
  85. )   Greater
  86. (:  Less or Equal
  87. ):  Greater or Equal
  88.  
  89. Assignment statements consisted of an object, the assignment operator and
  90. an expression. The expression consisted of one operand or two operands
  91. separated by an arithmetic operator. An operand was either a number or
  92. an object with an optional unary minus operator. 
  93. Below are two assignment statements
  94.  
  95. .9 (- ,5
  96. .8 (- .9 )( -,33333333
  97.  
  98. The first assigns 1/2 to register 9, the second one multiplies register 9 by 
  99. 1/3 and assigns that to register 8. 
  100.  
  101.  
  102. THE PROGRAM OBJECTS
  103.  
  104. The kvikkalkul objects are registers, data pointers, program pointers
  105. and channels. They are denoted by a special symbol followed by a
  106. digit.
  107.  
  108. There are 10 objects of each type, numbered from 0 to 9. In fact there
  109. were 16 of each, but the other six were secret and for internal use
  110. by the library routines only. 
  111.  
  112. 1 REGISTERS
  113.  
  114. A register can store one number. Registers are denoted by a period(.) followed
  115. by a digit. Registers my be used in assignment statements and as
  116. operands in conditional jump statements. 
  117.  
  118. 2 DATA POINTERS
  119.  
  120. A data pointer points to a data area in memory. Data pointers are denoted
  121. by a slash (/) followed by a digit. Data pointers may be used as registers
  122. in assignment statements and conditional jump statements. The contents of the
  123. memory location the data area points to are used in that case. Before
  124. you can use a data pointer that way, you have to make it point to
  125. a memory location and you have to reserve memory for it.
  126.  
  127. The statement 
  128.  
  129. 333/ 44
  130.  
  131. declares a storage area for 44 numbers with the label 333. 
  132.  
  133. /0 -) 333
  134.  
  135. makes data pointer 0 point to the first number in that area.
  136.  
  137. /0 (- ,127
  138.  
  139. stores the number ,127 into that location. 
  140.  
  141. /0 ))
  142.  
  143. makes data pointer 0 point to the next location in that area.
  144.  
  145. /0 (( 
  146.  
  147. makes it point to the previous location.
  148.  
  149. Making the pointer point to a random location in the data area, it a bit
  150. tricky. First you have to determine the smallest power of two that is not
  151. less than the size of the data area. For area 333, that is 64. To point to
  152. location n (counting from zero) you have to use a number that's n/64, 
  153. e.g. location 16 is the number ,25 The following statement makes the
  154. pointer point to the desired location.
  155.  
  156. /0 -) 333 ,25 
  157.  
  158. The second operand may also be a register or a data pointer.
  159.  
  160. 3 PROGRAM POINTERS
  161.  
  162. A program pointer points to a location in the program. Program pointers are 
  163. denoted by a colon (:) followed by a digit. Program pointers cannot
  164. be used as ordinary operands in assignment statements and such. 
  165.       
  166. You can declare labels in your program and you can make program pointers
  167. point to them. Then you can jump to those pointers.
  168.  
  169. The statement
  170.  
  171. 4400: 
  172.  
  173. declares a program label 4400:
  174.  
  175. :2 -) 4400
  176.  
  177. makes program pointer 2 point to label 4400.
  178.  
  179. -) :2
  180.  
  181. jumps to program pointer 2, in this case it's the label 4400.
  182.  
  183. Program pointer 0 is the default subroutine return address.  
  184. Look at the following program.
  185.  
  186. .0 (- ,375
  187. :0 -) 6000
  188. :1 -) 100
  189. -) :1
  190. 6000:
  191.  
  192. First a value is assigned to register 0. Then program pointer 0 is made
  193. to point to label 6000. Then program pointer 1 is made to point to label 100.
  194. Next that pointer is jumped to. At label 100 there is the standard subroutine
  195. to print the contents of register 0 to the teletype. After that's
  196. done the subroutine jumps to program pointer 0, and that's label 6000.
  197.  
  198. There is also a conditional jump, which consists of two operands separated
  199. by a relational operator followed by an ordinary jump statement.
  200.  
  201. .0 ( ,0 -) :4
  202.  
  203. means jump to program pointer 4 if register 0 is less than zero.
  204.  
  205. There are also program pointer storage areas. You declare them as
  206. data storage areas but with /: instead of /
  207.  
  208. 666/: 32
  209.  
  210. reserves a program pointer storage area for 32 pointers. 
  211. You can set a data pointer to this area. If you do this it is illegal
  212. to use that data pointer for data, but now it is legal to assign
  213. program pointers to the data pointer and back.
  214.  
  215. :3 -) 7777
  216. /4 (- :3
  217.  
  218. stores the label 7777 (through program pointer 3) into the location the
  219. data pointer 4 points to.
  220.  
  221. :5 (- /4
  222.  
  223. sets program pointer 5 to the contents of the memory location the
  224. data pointer points to, in this case label 7777
  225.  
  226. 4 CONSTANTS
  227.  
  228. Constants are just constants. These are quantities that are hard to
  229. type otherwise. A constant is denoted by a quote(") followed by a digit.
  230. They may be used as ordinary arithmetic operands, but not on the
  231. left hand side of an assignment.
  232.  
  233. "0 is the minimum number ( -,9999999999999999)
  234. "1 is the smallest distance between two numbers ( 2^-14)
  235. "2 is the special overflow value.
  236. "3 is 1/pi
  237. "4 is ln 2
  238. "5 is 1/32 
  239. "6 is 1/sqrt(2)
  240. "7 is sqrt(3)/2 
  241. "8 is log 2 (base 10)
  242. "9 is the maximum number (  ,9999999999999999)
  243.  
  244. 5 CHANNELS
  245.  
  246. Channels are the input/output devices of the computer. Channels are
  247. denoted by surrounding a digit with parentheses. Channels may be used as
  248. operands in arithmetic expressions and conditional jump statements. In
  249. this case the channel is read. They may also be used as the left hand side
  250. of an assignment expression. In this case a value is written to the
  251. channel.
  252.  
  253. (0) is the teletype channel. The value sent to it/ received from it
  254. is the binary value of the Baudot code divided by 32. If the channel is read
  255. and no character is available, a negative value is returned.
  256.  
  257. (1) is the paper tape channel. Same remarks as for (0). 
  258.  
  259. (2) is the real time clock. It can only be read. Runs from "0 to "9 in
  260. one hour, then returns to "0 again.
  261.  
  262. (3) was the random number generator. It could only be read. This was
  263. implemented using germanium noise diodes and it was very unreliable.
  264. If it ran hot, it returned all 1 bits (overflow value) almost all the time.
  265. Its use was highly discouraged.
  266.  
  267. (4) to (7) are connected to radar, torpedoes or whatever stuff the
  268. computer is supposed to control.
  269.  
  270.  
  271. The statement 
  272. (0) (- ,03125
  273.  
  274. sends Baudot code 1 to the teletype.
  275.  
  276. PROGRAM AND DATA LABELS
  277.  
  278. Data areas and program pointer storage areas are denoted by numeric
  279. labels in the range 0--32767. The labels above 30000 are reserved for
  280. internal use only and may not be used. A program pointer
  281. storage area and a data area may not have the same label.
  282.  
  283. Program labels are numbers in the range 0--32767. Numbers below 1000
  284. are reserved for standard subroutines. Numbers above 30000 are
  285. reserved for internal use only and may not be used.
  286.  
  287. Note that kvikkalkul does not have integers or scaled fractions. But
  288. some of the library routines treat their arguments as if they were 
  289. scaled fractions in the range (-256,256) or integers in the
  290. range (16383,16383).
  291.  
  292. Some of the library routines I still remember are.
  293.  
  294. 11 Multiply integers .0 is .0 times .1
  295. 12 Divide integers. .0 is .0 div .1
  296.  
  297. 21 convert fraction to scaled fraction.
  298. 22 convert fractional part of scaled fraction to fraction. 
  299.  
  300. 31 Multiply scaled fractions. 
  301. 32 Divide scaled fractions. 
  302.  
  303. 48 Wait until character ready on teletype, read to .0
  304. 49 same for paper tape.
  305.  
  306. 100 Writes the contents of .0 to the teletype in decimal fraction format.
  307. 101 same for paper tape.
  308. 150 Reads a decimal fractional number from the teletype to .0 
  309. 151 same for paper tape.
  310. 200 send CRLF to teletype
  311. 201 same for paper tape
  312. 250 wait until CRLF received from teletype
  313. 251 same for paper tape.
  314.  
  315. 300/301 350/351 Number read/write routines for integers in the range
  316. -16383 .. 16383. 
  317.  
  318. 302/303 352/353 Same for Scaled fractions (-256,256)
  319.  
  320. 400 square root. (argument and result in .0)
  321. 450 Sine (where -1..1 as argument was interpreted as -180..180 degrees)
  322. 460 Cosine.
  323. 470 Arctan (argument is scaled fraction, result is scaled to (-1,+1)
  324. 480 Log (1+x) (base 2)
  325. 490 2^x-1 
  326.  
  327. 530 Read a line from the teletype into memory pointed to by /0, one
  328.     character per number 0..1 in steps of ,03125
  329. 531 Same for paper tape.
  330. 540 Write a line to paper tape from memory pointed to by /0, one
  331.     character per number.
  332. 541 Same for paper tape.
  333. 550/551 560/561 Line read/write routines that packed three characters
  334.     per number, first was 5 most significant bits. These were
  335.     stored more efficiently but a HELL to process, as negatives, positives
  336.     and even overflow was a valid character triplet.    
  337.     
  338. 900 Read hour number to .0 Must be called at least twice an hour, because
  339. it relies on the positive/negative transition of (2) to increment the internal
  340. hour number. 
  341.  
  342. 666 emergency stop.
  343.  
  344. 888 Dump internal program state to paper tape and stop. Many programs
  345.     needed to do a lot of processing to initialize tables. If text strings
  346.     were needed, they were read from teletype and/or paper tape and
  347.     not written in the program itself. So each nontrivial program had an
  348.     initialization phase in which it read data and computed numbers
  349.     for tables. Then the program called 888. The resulting dump
  350.     could be used by the kvikkalkul compiler to generate a program
  351.     with all tables already initialized. 
  352.     
  353. KVIKKALKUL TODAY
  354.  
  355. I left the Swedish Navy in 1958 and now I live in a country whose name I 
  356. rather not tell. I fear that I will be extradited to Sweden if the 
  357. Swedish authorities see this message. What I described was the state of
  358. kvikkalkul in 1958. What I tell in this section is based on rumours,
  359. on tiny pieces of information I got from colleagues and on intelligent
  360. guesswork.
  361.  
  362. Kvikkalkul is still in use today, at least that was the case in 1991. 
  363. There is an Ada to kvikkalkul translator and most new programs are
  364. written in Ada and then translated to kvikkalkul. The kvikkalkul
  365. version was the definitive program that was reviewed, approved,
  366. tested and maintained. There was also a Simula to kvikkalkul translator
  367. in the 70s and some programs were written with it. 
  368.  
  369. Some changes have been made to the language.
  370. The guaranteed precision of numbers was increased over the years and
  371. is now at least 32 bits. Valid label numbers are now in the range
  372. 0..4000000000 with some haphazard reserved areas for library routines and
  373. internally used labels. Most library routines that are widely used today
  374. lie in the range 60001-65535. I have no details of them. 
  375.  
  376. The language itself remained remarkably constant. It's still a language
  377. without letters and the smiley notation for operators in still in use,
  378. though for source text the angle brackets may be used instead of parentheses
  379. and + and = are valid substitutes for the -/- and :: operators. Now
  380. new construct have been added and the only data type in the language
  381. is still the fixed point fractional number.  Channel number 3 for
  382. the random generator has been deleted and numbers 8 and 9 were added.
  383.  
  384. Channel 9 is the OS supervisory channel. By sending messages to it, you can 
  385. assign arbitrary files to the channels 0, 1, and 3 through 7. You can
  386. specify the character conversion type of the channels. It is possible
  387. to connect channel 0 to an ASCII terminal and convert all incoming
  388. characters to (more or less) Baudot equivalents and convert all outgoing
  389. Baudot characters back to ASCII. In fact this is the default
  390. for channels 0 and 1. All typical OS services can be accessed through
  391. channel 9.
  392.  
  393. Channel 8 is the floating point processor. You can send numbers and 
  394. opcodes to it and retrieve the computed results. The numbers that you
  395. send to it are 32-bit fractionals that bear no relationship to the FP
  396. numbers as the FP processor sees them. There are library routines
  397. for printing and reading them. The 640000 type standard FP library
  398. calls were made obsolete by channel 8. They still work.
  399.  
  400. An ex-colleague of mine tried my accounting package from 1958 on
  401. a modern kvikkalkul compiler in 1991. It still works flawlessly, except
  402. that the year cannot be set beyond 1973. He had to retype the program
  403. by hand as there was no suitable 5-bit Baudot paper tape reader for
  404. the system. 
  405.  
  406. -------------------------------------------------------------------------
  407. To find out more about the anon service, send mail to help@anon.penet.fi.
  408. Due to the double-blind, any mail replies to this message will be anonymized,
  409. and an anonymous id will be allocated automatically. You have been warned.
  410. Please report any problems, inappropriate use etc. to admin@anon.penet.fi.
  411.  
  412.